package com.kidedu.action;


import javax.servlet.http.HttpServletRequest;


import org.apache.struts2.ServletActionContext;

import com.kidedu.entity.KAdmin;
import com.kidedu.service.IKAdminService;

import com.kidedu.util.SpringContextUtil;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

import net.sf.json.JSONObject;

public class KAdminAction {

	
	private String username;
	private String password;
	private JSONObject json=new JSONObject();
	private IKAdminService kAdminService=(IKAdminService)SpringContextUtil.getBean("iKAdminService");
	
	/**
	 * login 
	 * @return
	 */
	
	public String AdminLoginOut()
	{
	    HttpServletRequest req = ServletActionContext.getRequest();
		req.getSession().removeAttribute("ADMIN");
		return Action.SUCCESS;
	}
	public String AdminLogin()
	{
		
	   KAdmin admin=kAdminService.login(username, password);
	  
	   if(null==admin)
		   return "fail";
	     ActionContext.getContext().getSession().put("ctx", ServletActionContext.getServletContext().getContextPath());
	    HttpServletRequest req = ServletActionContext.getRequest();

		req.getSession().setAttribute("ADMIN", admin);
		
		return Action.SUCCESS;
	}
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public JSONObject getJson() {
		return json;
	}
	public void setJson(JSONObject json) {
		this.json = json;
	}
	
}
